package com.weblog.model.user;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

@Entity
@Table(name = "tb_admin")
public class Admin implements Serializable {
    private static final long serialVersionUID=-4678122923451943999L;

    /**
     * 管理员id
     */
    @Id
    private String id;

    /**
     * 管理员用户名(登录账号)
     */
    private String username;

    /**
     * 管理员姓名
     */
    private String name;

    /**
     * 管理员密码
     */
    private String password;

    /**
     * 是否为超级管理员
     * 超级管理员只有一个
     * 后添加的均不是超级管理员
     */
    private String issuper;
    /**
     * 最后登录时间
     */
    private Date lastlogin;


    private String state;



    @JsonIgnoreProperties(value = {"admins","permissions"})
    @ManyToMany(targetEntity = Role.class,fetch = FetchType.EAGER)
    @JoinTable(name = "tb_ur",
            joinColumns = {@JoinColumn(name = "aid",referencedColumnName = "id")},
            inverseJoinColumns = {@JoinColumn(name = "rid",referencedColumnName = "rid")}
    )
    private Set<Role> roles=new HashSet<>();


    @Override
    public String toString() {
        return "Admin{" +
                "id='" + id + '\'' +
                ", username='" + username + '\'' +
                ", name='" + name + '\'' +
                ", password='" + password + '\'' +
                ", issuper='" + issuper + '\'' +
                ", lastlogin=" + lastlogin +
                ", state='" + state + '\'' +
                ", roles=" + roles +
                '}';
    }

    public Set<Role> getRoles() {
        return roles;
    }

    public void setRoles(Set<Role> roles) {
        this.roles = roles;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Date getLastlogin() {
        return lastlogin;
    }

    public void setLastlogin(Date lastlogin) {
        this.lastlogin = lastlogin;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getIssuper() {
        return issuper;
    }

    public void setIssuper(String issuper) {
        this.issuper = issuper;
    }
}
